from re import search

if __name__ == '__main__':
    pattern = "this"
    text = "Does this text match the pattern?"

    match = search(pattern=pattern, string=text)

    if match is not None:
        # 获取匹配对象在输入字符串的开始位置
        s = match.start()
        # 获取匹配对象在输入字符串的结束位置
        e = match.end()

        print('Found "{}"\nin "{}"\nfrom {} to {} ("{}")'.format(match.re.pattern, match.string, s, e, text[s:e]))

    else:
        print("没有匹配")
